package blobDetector;

import java.util.Vector;

import processing.core.PApplet;
import processing.core.PImage;

public class BlobApplet extends PApplet {
	PImage img;

	float iso = 200;
	BlobDetector bD;

	
	float[] brightness;
	public void setup() {
		size(640, 480);
		img = loadImage("plan.png");
		bD=new BlobDetector(img.width,img.height);
		 brightness=new float[img.pixels.length];
		for (int i=0;i<img.pixels.length;i++){
			int color=img.pixels[i];
			brightness[i]=brightness(color);
		}
		bD.setValues(brightness);
	}

	
	
	public void draw() {
		bD.calculateBlobsFloat(100);
		Vector<Blob> blobs = bD.getBlobs();

		scale(5);
		image(img, 0, 0);
		noFill();
		// rectMode(CENTER);
		
		strokeWeight(0.1f);

		for (int i = 0; i < blobs.size(); i++) {
			stroke(255, 0, 0);
			Blob blob = blobs.get(i);
			Vector<BlobCell> borders = blob.getBorders();
			for (int j = 0; j < borders.size(); j++) {
				BlobCell cell1 = borders.get(j);
				BlobCell cell2 = borders.get((j + 1) % borders.size());
				line(cell1.getX() , cell1.getY() ,
						cell2.getX() , cell2.getY() );
			}
			
			stroke(255, 255, 0);
			rect(blob.getMinX(),blob.getMinY(),blob.getWidth(),blob.getHeight());
		}
		/*
		 * for (int x = 0; x < grid.length; x++) { for (int y = 0; y <
		 * grid[x].length; y++) { Cell cell = grid[x][y]; if
		 * (checkIfBorder(cell) == true) { fill(255, 0, 0); rect(cell.getX(),
		 * cell.getY(), 1, 1); }
		 * 
		 * } }
		 */
	}

	
}
